package com.web.boot;

import org.tio.http.common.HttpConfig;
import org.tio.http.server.HttpServerStarter;
import org.tio.http.server.handler.DefaultHttpRequestHandler;
import org.tio.http.server.mvc.Routes;

import com.app.conf.AppConf;
import com.app.conf.info.Conf;

public class Startup
{
	public static void main(String[] args) throws Exception
	{
		// 基础服务
		AppConf.init().start();

		// http服务配置
		HttpConfig httpConfig = new HttpConfig(Integer.parseInt(System.getProperty("serverPort")), null, null, null);
		httpConfig.setPageRoot(System.getProperty("user.dir") + Conf.www);// 网页根
		httpConfig.setMaxLiveTimeOfStaticRes(0);
		httpConfig.setPage404("/404.html");
		httpConfig.setPage500("/500.html");
		httpConfig.setUseSession(false);

		// 启动Http服务
		new HttpServerStarter(httpConfig,new DefaultHttpRequestHandler(httpConfig, new Routes(new String[] { "com.app.controller" }))).start();

		Runtime.getRuntime().addShutdownHook(new Thread() {
			public void run() 
			{
				AppConf.init().stop();
			}
		});
	}
}